<?php

namespace app\admin\service;

use app\admin\dao\MemberDao;
use app\admin\model\UM as UM;
use app\common\model\Member;
use ShidianUtil\Exception\DataNotExistException;

/**
 * Class MemberLockService
 * @package app\member\service
 */
class MemberLockService
{

    private MemberDao $memberDao;

    public function __construct(MemberDao $memberDao)
    {
        $this->memberDao = $memberDao;
    }

    /**
     * 更新
     * @param \app\admin\model\UM $user
     * @param int $id
     * @param array $params
     * @return \app\common\model\Member
     */
    public function modify(UM $user, int $id, array $params): Member
    {
        $params['status'] = $params['status'] == 1 ? 1 : 0;

        $record = Member::field(true)->where('id', $id)->find();

        if (is_null($record)) {
            throw new DataNotExistException('该用户不存在或已被删除');
        }

        $record->disabledUserId = $user->id;
        $record->disabledActionTime = time();
        $record->status = $params['status'];
        $record->save();

        return $record;
    }

}
